package com.SmartCare.common.dto.role;

import com.SmartCare.pojo.role.ElderlyInformation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * @author young
 * @since 2023-10-18
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class ElderManagerDTO implements Serializable {

    /**
     * 老人总数
     */
    private Integer total;

    /**
     * 可以自理老人数
     */
    private Integer selfCareCount;

    /**
     * 八十岁以上老人数
     */
    private Integer overEighty;

    //构造
    // 构造
    public ElderManagerDTO(List<ElderlyInformation> list) {
        // 获取总数
        this.total = list.size();
        // 获取可自理人数
        if(list.size() == 0){
            this.selfCareCount = 0;
            this.overEighty = 0;
        }else{
            this.selfCareCount = (int) list.stream()
                    .filter(elderly -> elderly.getSelfCareAbility() != null && elderly.getSelfCareAbility() == 1)
                    .count();
            // 获取超过八十岁人数
            this.overEighty = (int) list.stream()
                    .filter(elderly -> elderly.getAge() != null && elderly.getAge() >= 80)
                    .count();
        }

    }

}
